/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulation;

/**
 *
 * @author Danielondon
 */
public class CommonResources {
    public static int CONNECTED = 1;
    public static int DISCONNECTED = 0;
    public static int DEFAULT_INTERVAL = 60; // 15 min
    public static String STRING_SEPARATOR = ";";
    public static String STRING_SEPARATOR_PARAMETERS = "&";
    public static String SIMULATION_CONVERSATION_ID = "simulation";
    public static String DEFAULT_CURRENCY = "euro";
    public static String BASE_CURRENCY = "dollar";
    private static double EurosPerOneDollar = 0.75;
    private static double DollarsPerOneEuro = 1.33;
    public static Object[] ParametersToObjectArray(String parameters) {
        String [] tokens = parameters.split(STRING_SEPARATOR_PARAMETERS);
        Object[] objectParameters;
        objectParameters = new Object[tokens.length];
        for(int i =0; i < tokens.length; i++){
            objectParameters[i] = tokens[i];
        }
        return tokens;
    }

    public static String ParametersToString(Object[] arguments) {
        String returnParameters = "";
        for(int i =0; i < arguments.length; i++){
            returnParameters += arguments[i].toString() + CommonResources.STRING_SEPARATOR_PARAMETERS;
        }
        return returnParameters;
    }
    
    
    public static double convertPrice(String fromCurrency, String toCurrency, double value) throws Exception{
        // From Dollar to Euro
        if (fromCurrency.equals(BASE_CURRENCY)){
            if (toCurrency.equals(DEFAULT_CURRENCY)){
                return value * EurosPerOneDollar;
            }
        }
        
        // From Euro to Dollar
        if (fromCurrency.equals(DEFAULT_CURRENCY)){
            if (toCurrency.equals(BASE_CURRENCY)){
                return value * DollarsPerOneEuro;
            }
        }
        
        throw new Exception ("The currencies are not supported");
    }

    static String replaceText(String line, String textToReplace, String newText) {
        int index = line.indexOf(textToReplace);
        StringBuilder newFileName = new StringBuilder(line);
        if (index != -1) {
            newFileName =  newFileName.replace(index, index + textToReplace.length(), newText);
        }
        return newFileName.toString();
    }
}
